<template>
  <div class="addcommon-content">
    <input type="text" placeholder="评论" v-model="message" />
    <span class="fabiao-box" @click="toComment">发表</span>
  </div>
</template>

<script>
import { addDynamicCooment } from "network/dynamic";

import { mapState } from "vuex";

export default {
  name: "",
  props: {
    dynaId: {
      type: String,
      default: () => "",
    },
  },
  data() {
    return {
      message: "",
    };
  },
  methods: {
    toComment() {
      let context = this.message;
      let dynaId = this.dynaId;
      let userId = this.userId;
      if (this.userId == null) {
        console.log(this.userId);
        this.$toast({
          message: "请登录后评论",
          position: "bottom",
        });
        this.$router.push("/login");
        return;
      }
      addDynamicCooment({ context, dynaId, userId }).then((res) => {
        console.log(res);
      });
    },
  },
  computed: {
    ...mapState({
      userId: (state) => state.moduleUser.userId,
    }),
  },
};
</script>

<style scoped>
.addcommon-content {
  padding-left: 65px;
  padding-right: 20px;
}
.addcommon-content input {
  width: 80%;
  border: none;
  outline: none;
  font-size: 12px;
  background-color: rgb(247, 247, 247);
  height: 22px;
  border-radius: 2px;
  text-indent: 5px;
}
.fabiao-box {
  display: inline-block;
  font-size: 12px;
  margin-left: 2px;
  height: 22px;
  background-color: rgb(240, 240, 240);
  padding: 0 3px;
  border-radius: 2px;
  line-height: 22px;
}
</style>